/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simhya.matheval;

import java.util.ArrayList;

/**
 *
 * @author Luca
 */
public class VariableNode extends ExpressionNode {
    int varIndex;
    SymbolArray varReference;
    String name;
    



    public VariableNode(int varIndex, SymbolArray varReference) {
        super(0);
        if (!varReference.checkSymbolIndex(varIndex))
            throw new EvalException("Variable index is wrong");
        this.varIndex = varIndex;
        this.varReference = varReference;
        name = varReference.getName(varIndex);
    }


    public void setName(String name) {
        this.name = name;
    }

    @Override
    public void getListOfVariables(ArrayList<Integer> list) {
        list.add(varIndex);
    }

    @Override
    String getExpressionString(boolean fullNumberRepresentation) {
        return this.name;
    }

    @Override
    void computeValue() {
        super.value = varReference.values[varIndex];
    }

    @Override
    void computeValue(SymbolArray varReference) {
        super.value = varReference.values[varIndex];
    }

    @Override
    void computeValue(int evaluationCode) {
        super.value = varReference.values[varIndex];
    }

    @Override
    void computeValue(SymbolArray varReference, int evaluationCode) {
        super.value = varReference.values[varIndex];
    }

}
